<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <link rel="shortcut icon" href="../../favicon.ico" type="image/x-icon">
    <link rel="stylesheet" type="text/css" href="../../css/reset.css" />
    <link rel="stylesheet" type="text/css" href="../../css/login.css" />
</head>

<body>
    <div class="pos">
        <div class="login">
            <span class="close iconfont icon-close"></span>
            <img src="../../img/login/loginlogo.png" alt="">
            <ul>
                <li></li>
                <li class="phone">登陆</li>
                <li></li>
            </ul>
            <!-- <form action="" id="form"> -->
                <input style="margin-top: 0;" type="text" name="tel" class="tel" id="username" placeholder="请输入您的手机号">
                <input type="password" name="pass" class="pass" id="password" placeholder="请输入密码">
                <span class="tips"> </span>
                <button class="loginbtn">
                    登陆
                </button>
            <!-- </form> -->
            <p>
                <span>
                    还没有账号?
                    <a href="javascript:;">点击注册</a>
                </span>
            </p>
        </div>
    </div>
    <!-- <script src="../../utils/utils.js"></script> -->
</body>
</html>
<script src="../../utils/jquery.min.js"></script>
<script src="../../utils/ajax.js"></script>
<script>

    $(".loginbtn").on("click",async function(){
        $(".tips").text("")

        let username = $("#username").val()
        let password = $("#password").val()

        if(!username||!password) {
            $(".tips").text("请输入账号或密码")
            return
        }

      
   
        // 发送ajax请求
        let [err,results]=await ajax({
            type:"post",
            url:api_url+"/login",
            data:{
                username,
                password
            }
        })



        if(err){
            $(".tips").text("出错了")
            return
        }

        if(results.status!=200){
            $(".tips").text( results.msg)
            return
        }


        
        // console.log(err,results);
        // 登录成功。使用本地存储把token存储下来
        localStorage.setItem("t",results.token)


        alert("登录成功")
        // location.href="../../index.html"
        location.href="../userSeting.html"

    })


</script>